--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Commit bd6fe9f9d1e2095fd77eedad1cc406418198dc1e
Parents : 0f2d3b0
Author : Mark Qvist <mark@unsigned.io>
Date : 2025-10-30T15:39:00+01:00
Handle propagation node stamp cost peering signalling
Changes
3 files changed, 29 insertions(+), 23 deletions(-)
Diff
diff --git a/LXMF/Handlers.py b/LXMF/Handlers.py
index 793ba16..41b3200 100644
--- a/LXMF/Handlers.py
+++ b/LXMF/Handlers.py
@@ -45,42 +45,35 @@ class LXMFPropagationAnnounceHandler:
if self.lxmrouter.propagation_node:
data = msgpack.unpackb(app_data)
if pn_announce_data_is_valid(data):
- node_timebase = data[1]
- propagation_transfer_limit = None
- propagation_sync_limit = None
- wanted_inbound_peers = None
- if len(data) >= 5:
- try: propagation_sync_limit = int(data[4])
- except Exception as e: propagation_sync_limit = None
-
- if len(data) >= 4:
- # TODO: Rethink, probably not necessary anymore
- # try: wanted_inbound_peers = int(data[3])
- # except: wanted_inbound_peers = None
- pass
-
- if len(data) >= 3:
- try: propagation_transfer_limit = float(data[2])
- except: propagation_transfer_limit = None
-
+ pn_active = data[0]
+ node_timebase = int(data[1])
+ propagation_transfer_limit = int(data[2])
+ propagation_sync_limit = int(data[3])
+ propagation_stamp_cost = int(data[4][0])
+ propagation_stamp_cost_flexibility = int(data[4][1])
+
if destination_hash in self.lxmrouter.static_peers:
self.lxmrouter.peer(destination_hash=destination_hash,
timestamp=node_timebase,
propagation_transfer_limit=propagation_transfer_limit,
propagation_sync_limit=propagation_sync_limit,
+ propagation_stamp_cost=propagation_stamp_cost,
+ propagation_stamp_cost_flexibility=propagation_stamp_cost_flexibility,
wanted_inbound_peers=wanted_inbound_peers)
else:
if self.lxmrouter.autopeer:
- if data[0] == True:
+ if pn_active == True:
if RNS.Transport.hops_to(destination_hash) <= self.lxmrouter.autopeer_maxdepth:
self.lxmrouter.peer(destination_hash=destination_hash,
timestamp=node_timebase,
propagation_transfer_limit=propagation_transfer_limit,
propagation_sync_limit=propagation_sync_limit,
+ propagation_stamp_cost=propagation_stamp_cost,
+ propagation_stamp_cost_flexibility=propagation_stamp_cost_flexibility,
wanted_inbound_peers=wanted_inbound_peers)
- elif data[0] == False:
+ elif pn_active == False:
self.lxmrouter.unpeer(destination_hash, node_timebase)
except Exception as e:
diff --git a/LXMF/LXMF.py b/LXMF/LXMF.py
index 93e283f..8d1aaf7 100644
--- a/LXMF/LXMF.py
+++ b/LXMF/LXMF.py
@@ -138,11 +138,20 @@ def stamp_cost_from_app_data(app_data=None):
def pn_announce_data_is_valid(data):
try:
if type(data) == bytes: data = msgpack.unpackb(data)
- if len(data) < 3: raise ValueError("Invalid announce data: Insufficient peer data")
+ if len(data) < 5: raise ValueError("Invalid announce data: Insufficient peer data")
else:
if data[0] != True and data[0] != False: raise ValueError("Invalid announce data: Indeterminate propagation node status")
try: int(data[1])
except: raise ValueError("Invalid announce data: Could not decode peer timebase")
+ try: int(data[2])
+ except: raise ValueError("Invalid announce data: Could not decode peer propagation transfer limit")
+ try: int(data[3])
+ except: raise ValueError("Invalid announce data: Could not decode peer propagation sync limit")
+ if type(data[4]) != list: raise ValueError("Invalid announce data: Could not decode peer stamp costs")
+ try: int(data[4][0])
+ except: raise ValueError("Invalid announce data: Could not decode peer target stamp cost")
+ try: int(data[4][1])
+ except: raise ValueError("Invalid announce data: Could not decode peer stamp cost flexibility")
except Exception as e:
RNS.log(f"Could not validate propagation node announce data: {e}", RNS.LOG_DEBUG)
diff --git a/LXMF/LXMRouter.py b/LXMF/LXMRouter.py
index 5c02cf0..eef9fee 100644
--- a/LXMF/LXMRouter.py
+++ b/LXMF/LXMRouter.py
@@ -288,8 +288,8 @@ class LXMRouter:
node_state, # Boolean flag signalling propagation node state
int(time.time()), # Current node timebase
self.propagation_per_transfer_limit, # Per-transfer limit for message propagation in kilobytes
- stamp_cost, # Propagation stamp cost for this node
self.propagation_per_sync_limit, # Limit for incoming propagation node syncs
+ stamp_cost, # Propagation stamp cost for this node
]
data = msgpack.packb(announce_data)
@@ -1783,7 +1783,7 @@ class LXMRouter:
### Peer Sync & Propagation ###########################
#######################################################
- def peer(self, destination_hash, timestamp, propagation_transfer_limit, propagation_sync_limit, wanted_inbound_peers = None):
+ def peer(self, destination_hash, timestamp, propagation_transfer_limit, propagation_sync_limit, propagation_stamp_cost, propagation_stamp_cost_flexibility):
if destination_hash in self.peers:
peer = self.peers[destination_hash]
if timestamp > peer.peering_timebase:
@@ -1792,6 +1792,8 @@ class LXMRouter:
peer.next_sync_attempt = 0
peer.peering_timebase = timestamp
peer.last_heard = time.time()
+ peer.propagation_stamp_cost = propagation_stamp_cost
+ peer.propagation_stamp_cost_flexibility = propagation_stamp_cost_flexibility
peer.propagation_transfer_limit = propagation_transfer_limit
if propagation_sync_limit != None: peer.propagation_sync_limit = propagation_sync_limit
else: peer.propagation_sync_limit = propagation_transfer_limit
@@ -1803,6 +1805,8 @@ class LXMRouter:
peer = LXMPeer(self, destination_hash, sync_strategy=self.default_sync_strategy)
peer.alive = True
peer.last_heard = time.time()
+ peer.propagation_stamp_cost = propagation_stamp_cost
+ peer.propagation_stamp_cost_flexibility = propagation_stamp_cost_flexibility
peer.propagation_transfer_limit = propagation_transfer_limit
if propagation_sync_limit != None: peer.propagation_sync_limit = propagation_sync_limit
else: peer.propagation_sync_limit = propagation_transfer_limit
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────